<?
// +----------------------------------------------------------------------
// | 分销联盟-联盟信息管理页面
// +----------------------------------------------------------------------
// | Author: TongBC <50249101@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/03/06
// +----------------------------------------------------------------------
include_once("common/header.html");
include_once("common/left.html");
include_once("class/MemberAccount.class.php");
include_once("class/Alliance.class.php");

if(empty($_SESSION['alliance'])) exit("<script>window.location='home.html'</script>");
$memberID = $_SESSION['sid'];
$mem = new \pft\Member\MemberAccount($GLOBALS['le']);
$m_info = $mem->GetOne($memberID);

// 联盟信息
$sql="select * from `pft_distributor_union_SE` where fid=$memberID order by id desc limit 1";
$GLOBALS['le']->query($sql);
$a_info = $GLOBALS['le']->fetch_assoc();

// 处理比例值
$dratio = explode('|', $a_info['dratio']);

// 处理押金
$cash_pledge = explode("|", $a_info['cash_pledge']);
$cash_pledge_gx = $cash_pledge[0] / 100;
$cash_pledge_gy = $cash_pledge[1] / 100;
$cash_pledge_fx = $cash_pledge[2] / 100;

// $dratio_x = $dratio[2] + $dratio[3] + $dratio[4];
// $dratio_y = $dratio[5] + $dratio[6];

// $dratio[2] = round($dratio[2] / $dratio_x * 100);
// $dratio[3] = round($dratio[3] / $dratio_x * 100);
// $dratio[4] = 100 - $dratio[2] - $dratio[3];

// $dratio[5] = round($dratio[5] / $dratio_y * 100);
// $dratio[6] = 100 - $dratio[5];


// 获取省份
$sql="select n_code,province from `pft_area_code_concat` where parent_province=n_code";
$GLOBALS['le']->query($sql);
while($row = $GLOBALS['le']->fetch_assoc()){
	$row['inviterID'] = 0;
	$province[$row['n_code']] = $row;
}

// 获取当前已指定的代理商
$agents = array();
$sql="select d.id,d.darea_title,d.dtime,m.dname,d.darea_code,d.inviterID from pft_distributor_agency d left join pft_member m on d.inviterID=m.id where fid=$memberID and d.dstatus=0";
$GLOBALS['le']->query($sql);
while($row=$GLOBALS['le']->fetch_assoc()){
// print_r($row);
    if(isset($province[$row['darea_code']])){
		$agents['province'][] = $row;
		$province[$row['darea_code']]['inviterID'] = $row['inviterID'];
	}else{
		$agents['city'][] = $row;
	}
}
// print_r($agents);
// 获取联盟成员
$sql = "select m.dname,i.memberID from pft_union_member_info_SE i left join pft_member m on i.memberID=m.id where fid=$memberID and dstatus=0";
$GLOBALS['le']->query($sql);
while($row=$GLOBALS['le']->fetch_assoc()){
	$dStr.= $row['dname'].'&'.$row['memberID'].'|';
}
$dStr = rtrim($dStr, '|');


// 页面变量
$uid = $a_info['id'];// 联盟ID
$name = $a_info['dtitle'];// 联盟名称
$ratio = $dratio;// 分配比例
// $ratio_x = $dratio_x;// 联盟比
// $ratio_y = $dratio_y;// 邀请人
$protocol = $a_info['protocol'];// 协议

// 省份前端字符串
$pStr = '';
foreach($province as $data){
	$pStr .= $data['province'].'&'.$data['n_code'].'&'.$data['inviterID'].'|';
}
$pStr = rtrim($pStr, '|');


$debug = $_GET["debug"];
if(!isset($debug)){
	include('tpl/alliance.html');
}else{
	include('a/alliance_dev.html');
}

include("common/footer.html");
?>